<?php
	include_once(dirname(__DIR__) . "/include/dbconnection.php");
	
	class Post {
		private $post_id, $thread_id, $owner_userprofile_id, $creation, $sequence_number, $content;
		
		private $html;
		
		function Post($post_id) {
			$this -> loadPostFromDatabase($post_id);
		}
		
		private function loadPostFromDatabase($post_id) {
			$query = "SELECT post_id, thread_id, owner_userprofile_id, creation, sequence_number, content FROM t_post WHERE post_id = " . intval($post_id);
			$result = mysql_query($query);
			$row = mysql_fetch_assoc($result);
			
			$this -> post_id = $row['post_id'];
			$this -> thread_id = $row['thread_id'];
			$this -> owner_userprofile_id = $row['owner_userprofile_id'];
			$this -> creation = $row['creation'];
			$this -> sequence_number = $row['sequence_number'];
			$this -> content = $row['content'];
			
			mysql_free_result($result);
		}
	}
	
	function insertPost($thread_id, $owner_userprofile_id, $content) {
		$query = "INSERT INTO t_post (thread_id, owner_userprofile_id, creation, sequence_number, content) VALUES (". intval($thread_id) .", ". intval($owner_userprofile_id) .", NOW(), 0, \"". mysql_escape_string($content) ."\")";
		mysql_query($query);
	}
	
	function deletePost($post_id) {
		$query = "DELETE FROM t_post WHERE post_id = ". intval($post_id);
		mysql_query($query);
	}
?>